<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/31
 * Time: 15:26
 */
//一个手机上传图片到服务器的小程序
//  上传文件
$data=file_get_contents('11.jpg');
//var_dump($data);
$http_entity_body=$data;
$http_entity_type='application/x-www-form-urlencoded';
$http_entity_length = strlen($http_entity_body);
//echo $http_entity_length;
$host = '127.0.0.1';
$port = 80;
$path = '/study/input/upload/image.php';
$fp=fsockopen($host,$port, $error_no, $error_desc, 30);
if ($fp){
    fputs($fp, "POST {$path} HTTP/1.1\r\n");
    fputs($fp, "Host: {$host}\r\n");
    fputs($fp, "Content-Type: {$http_entity_type}\r\n");
    fputs($fp, "Content-Length: {$http_entity_length}\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $http_entity_body . "\r\n\r\n");
    $d='';
    while (!feof($fp)) {
        $d .= fgets($fp, 4096);   //fgets() 函数从文件指针中读取一行。
    }
    fclose($fp);
    echo $d;
}